﻿@{
    ViewBag.Title = "Site map tools";
    Layout = "~/Views/Shared/_Layout_Administration.cshtml";
}

<div id="main">

    <ul class="nav nav-tabs">
        <li>
        @Html.RouteLink("Site map", new { @controller = "Administration", @action = "SiteMap" })
            </li>
        <li class="active">
            @Html.RouteLink("Bad links", new { @controller = "Administration", @action = "BadLinks" })
        </li>
    </ul>

    <div class="preloader preloader"></div>
    <div class="preloader-replacement hide">
        <table class="table-striped">
            <thead>
                <tr>
                    <th>StatusCode
                    </th>
                    <th>FileType
                    </th>
                    <th>Uri
                    </th>
                    <th>ReferalUri
                    </th>
                </tr>
            </thead>
            <tbody data-bind="foreach: WebRequestPropertiesList">
                <tr>
                    <td data-bind="text: StatusCode"></td>
                    <td data-bind="text: STR_FileType"></td>
                    <td data-bind="text: Uri"></td>
                    <td data-bind="text: ReferalUri"></td>
                </tr>
            </tbody>
        </table>

    </div>
</div>


@section scripts{

    <script type="text/javascript">

        function WebRequestProperties(data) {
            this.Uri = ko.observable(data.Uri);
            this.ReferalUri = ko.observable(data.ReferalUri);
            this.StatusCode = ko.observable(data.StatusCode);
            this.Title = ko.observable(data.Title);
            this.STR_FileType = ko.observable(data.STR_FileType);
        }

        var self;


        function WebRequestPropertiesListViewModel() {
            self = this;
            self.WebRequestPropertiesList = ko.observableArray([]);

            self.loadDataFromServer = function () {
                $.getJSON("GetBadLinks", function (allData) {
                    var mappedWebRequestPropertiesList = $.map(allData, function (item) { return new WebRequestProperties(item) });
                    self.WebRequestPropertiesList(mappedWebRequestPropertiesList);

                    TogglePreloader('.preloader', '.preloader-replacement');
                });
            };

            self.loadDataFromServer();

        }

        ko.applyBindings(new WebRequestPropertiesListViewModel());

    </script>

}